<template>
  <div class="changePassword">
    <el-form ref="form" :model="form" label-width="110px" class="fixed-form">
      <el-form-item label="用户名">
        <el-input v-model="form.userId"></el-input>
      </el-form-item>
      <el-form-item label="输入原密码">
        <el-input v-model="form.oldPassword" type="password"></el-input>
      </el-form-item>
      <el-form-item label="输入新密码">
        <el-input v-model="form.password" type="password"></el-input>
      </el-form-item>
      <el-form-item label="确认新密码">
        <el-input v-model="form.repeatNewPassword" type="password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即修改</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<style>
</style>
<script>
  export default{
    name: 'changePassword',
    data(){
      return {
        form: {
          userId: '001',
          oldPassword: '',
          password: '',
          repeatNewPassword: '',
        },
        userId: '',
        oldPassword: '',
      }
    },
    mounted: function () {
      this.$nextTick(function () {
        this.init();
      })
    },
    methods: {
      init(){
        this.userId = '001';
        this.getPassword();
      },
      getPassword(){
        this.$http.get(this.$until.url + '/personInfo/getPersonInfo',
          {
            params: {
              userId: this.userId
            }
          }).then(response => {
          this.oldPassword = response.body.password
          //console.log(response)
        }, response => {
          console.log('服务器异常')
        });
      },
      onSubmit(){
        if (this.oldPassword == this.form.oldPassword) {
          this.$http.post(this.$until.url + '/personInfo/updatePersonInfo', this.form, {emulateJSON: true})
            .then(response => {
              this.$message({
                message: '修改成功',
                type: 'success'
              });
            }, response => {
              console.log('文件获取失败');
            });
        } else {
          this.$message({
            message: '原密码输入错误',
            type: 'warning'
          });
        }
      }
    }
  }
</script>
